<template>
	<view class="plate">
		<view class="content">
			<!-- 基本信息表格 -->
			<view class="info-grid">
				<!-- 第一行 -->
				<view class="grid-cell">
					<text class="label">事项:</text>
					<text class="value">{{datas.home.matters}}</text>
				</view>
				
				<!-- 第二行 -->
				<view class="grid-cell">
					<text class="label">日期:</text>
					<text class="value">{{datas.home.time}}</text>
				</view>
				
				<!-- 第三行 -->
				<view class="grid-cell ganzhi">
					<text class="label">干支:</text>
					<view class="value-group">
						<text>{{datas.home.ndry}}</text>
						<text>{{datas.home.ydry}}</text>
						<text>{{datas.home.rdry}}</text>
						<text>{{datas.home.sdry}}</text>
					</view>
				</view>
				
				<!-- 第四行 -->
				<view class="grid-cell kongwang">
					<text class="label">空亡:</text>
					<view class="value-group">
						<text>{{datas.home.NKongwang}}</text>
						<text>{{datas.home.YKongwang}}</text>
						<text>{{datas.home.RKongwang}}</text>
						<text class="highlight">{{datas.home.SKongwang}}</text>
					</view>
				</view>
				
				<!-- 第五行 -->
				<view class="grid-cell">
					<text class="label">节气:</text>
					<text class="value">{{datas.home.lastjq}}{{datas.home.jqdate}}</text>
				</view>
				
				<!-- 第六行 -->
				<view class="grid-cell info-header">
					<text>句首</text>
					<text>局数</text>
					<text>值符</text>
					<text>值使</text>
					<text>暗值使</text>
				</view>
				
				<!-- 第七行 -->
				<view class="grid-cell info-values">
					<text>{{datas.layout.SXshous}}{{'('+ datas.layout.Xshou +')'}}</text>
					<text>{{datas.layout.Yinyang}}{{datas.layout.Jnum}}</text>
					<text>{{datas.layout.Ddata.Menvoy.Ysymbol}}</text>
					<text>{{datas.layout.Ddata.Menvoy.Ymen}}</text>
					<text>{{datas.layout.Ddata.Aenvoy.BDmen}}</text>
				</view>
			</view>
			
			<!-- 九宫格排盘 -->
			<qimen-grid class="plate-section" :gridData="this.datas.layout.PData"/>
			<!-- <qimen-plate class="plate-section" /> -->
			
			<!-- 底部占位，防止内容被底部按钮遮挡 -->
			<view class="bottom-space"></view>
		</view>
		
		<!-- 底部固定按钮 -->
		<view class="footer">
			<button 
				type="primary" 
				@click="savePlate"
				class="save-btn"
			>
				保存当前盘
			</button>
		</view>
	</view>
</template>

<script>
	import Root from '../../common/js/root/root.js'
	// 引用SQLite-manger文件
	import dbUtils from '@/uni_modules/zjy-sqlite-manage/components/zjy-sqlite-manage/dbUtils.js'
	import { mapState, mapActions } from 'vuex'
	import { formatDate } from '@/utils/date'
	import QimenGrid from '@/components/qimen/QimenGrid.vue'
	import QimenPlate from '@/components/qimen/QimenPlate.vue'
	
	export default {  //声明组件 
		components: {
			QimenGrid,
			QimenPlate
		},
		data() {
			return {
				width: '40%',
				height: '100px',
				datas: [],
				matter: ''
			};
		},
		computed: {
			...mapState('qimen', [
				'currentDate',
				'plate',
				'shiChen',
				'ganZhi',
				'kongWang',
				'jieQi',
				'juShou',
				'juNumber',
				'zhiFu',
				'zhiShi',
				'anZhiShi'
			]),
			palaces() {
				return this.plate?.palaces || []
			}
		},
		methods: {
			...mapActions('qimen', ['calculatePlate']),
			formatDate,
			
			goBack() {
				uni.navigateBack()
			},
			
			savePlate() {
				this.calculatePlate()
				uni.showToast({
					title: '保存成功',
					icon: 'success'
				})
			}
		},
		onLoad(e) {
			this.datas.home = e;
			// this.datas.layout = layout.getQobject(e.sdry, e.lastjq, e.cdaynum,e.rdry);
			this.datas.layout = Root.getplate(e.lastjq,e.rdry,e.sdry);
			
			console.log('数据集合：'+this.datas.layout)
		},
		onShow() {
			// var datas =
		},
		//自动触发保存
		
	}
</script>

<style lang="scss" scoped>
.plate {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	background-color: #f5f5f5;
	position: relative; // 为固定定位的footer提供参考
	
	.header {
		padding: 20rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		border-bottom: 1rpx solid #eee;
		
		.title {
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
		}
		
		.save-btn {
			margin: 0;
			font-size: 24rpx;
		}
	}
	
	.content {
		flex: 1;
		padding: 20rpx;
		padding-bottom: 120rpx; // 为底部按钮留出空间
		
		.info-grid {
			background-color: #fff;
			border-radius: 12rpx;
			overflow: hidden;
			display: grid;
			grid-template-columns: 1fr;
			gap: 2rpx;
			background-color: #eee;
			
			.grid-cell {
				background-color: #fff;
				padding: 24rpx;
				display: flex;
				align-items: center;
				
				.label {
					width: 80rpx;
					color: #666;
					font-size: 28rpx;
				}
				
				.value {
					flex: 1;
					font-size: 28rpx;
					margin-left: 20rpx;
				}
				
				.value-group {
					flex: 1;
					display: grid;
					grid-template-columns: repeat(4, 1fr);
					gap: 10rpx;
					margin-left: 20rpx;
					
					text {
						text-align: center;
						font-size: 28rpx;
						
						&.highlight {
							color: #f56c6c;
						}
					}
				}
				
				&.info-header {
					background-color: #f8f8f8;
					display: grid;
					grid-template-columns: repeat(5, 1fr);
					gap: 10rpx;
					
					text {
						text-align: center;
						font-size: 26rpx;
						color: #dfb06e;
					}
				}
				
				&.info-values {
					display: grid;
					grid-template-columns: repeat(5, 1fr);
					gap: 10rpx;
					
					text {
						text-align: center;
						font-size: 28rpx;
					}
				}
			}
		}
		
		.plate-section {
			margin-top: 20rpx;
			border-radius: 12rpx;
			overflow: hidden;
		}
		
		.bottom-space {
			height: 40rpx; // 额外的底部间距
		}
	}
	
	.footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx 30rpx;
		background-color: #fff;
		box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
		z-index: 100;
		
		.save-btn {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 32rpx;
			border-radius: 8rpx;
		}
	}
}
</style>